//
//  UCNavigationBarSetting.swift
//  UICreate
//
//  Created by 范晓鑫 on 2021/10/27.
//

import UIKit

extension UCSetting where TargetType: UINavigationBar {
    ///样式
    public static func style(_ style: UIBarStyle) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.barStyle = style
        })
    }
    ///delegate
    public static func delegate(_ delegate: UINavigationBarDelegate) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.delegate = delegate
        })
    }
    ///是否半透明
    public static func translucent(_ translucent: Bool) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.isTranslucent = translucent
        })
    }
    ///items
    public static func items(_ items: [UINavigationItem]) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.items = items
        })
    }
    ///prefersLargeTitles
    @available(iOS 11.0, *)
    public static func largeTitles(_ prefers:Bool) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.prefersLargeTitles = prefers
        })
    }
    ///高亮色
    public static func tint(bar color:UIColor?) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.barTintColor = color
        })
    }
    ///setBackgroundImage(_ backgroundImage: UIImage?, for barPosition: UIBarPosition, barMetrics: UIBarMetrics)
    public static func bg(_ image:UIImage?,for position: UIBarPosition, metrics: UIBarMetrics = .default) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.setBackgroundImage(image, for: position, barMetrics: metrics)
        })
    }
    ///setBackgroundImage(_ backgroundImage: UIImage?, for barMetrics: UIBarMetrics)
    public static func bg(_ image:UIImage?, metrics: UIBarMetrics = .default) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.setBackgroundImage(image, for: metrics)
        })
    }
    /// shadowImage
    public static func shadow(_ image:UIImage?) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.shadowImage = image
        })
    }
    /// titleTextAttributes
    public static func title(attr:[NSAttributedString.Key : Any]?) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.titleTextAttributes = attr
        })
    }
    /// largeTitleTextAttributes
    @available(iOS 11.0, *)
    public static func large(attr:[NSAttributedString.Key : Any]?) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.largeTitleTextAttributes = attr
        })
    }
    /// setTitleVerticalPositionAdjustment(_ adjustment: CGFloat, for barMetrics: UIBarMetrics)
    public static func title(adjust: CGFloat, metrics: UIBarMetrics = .default) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.setTitleVerticalPositionAdjustment(adjust, for: metrics)
        })
    }
    ///backIndicatorImage
    public static func bgIndicator(_ image:UIImage?) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.backIndicatorImage = image
        })
    }
    ///backIndicatorTransitionMaskImage
    public static func bgIndicator(mask image:UIImage?) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.backIndicatorTransitionMaskImage = image
        })
    }
    ///standardAppearance
    @available(iOS 13.0, *)
    public static func appearance(_ appearance:UINavigationBarAppearance) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.standardAppearance = appearance
        })
    }
    ///compactAppearance
    @available(iOS 13.0, *)
    public static func appearance(compact appearance:UINavigationBarAppearance?) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.compactAppearance = appearance
        })
    }
    ///scrollEdgeAppearance
    @available(iOS 13.0, *)
    public static func appearance(scroll appearance:UINavigationBarAppearance?) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.scrollEdgeAppearance = appearance
        })
    }
    ///compactScrollEdgeAppearance
    @available(iOS 15.0, *)
    public static func appearance(compactScroll appearance:UINavigationBarAppearance?) -> UCSetting<TargetType> {
        return .init(action: { (target) in
            target.compactScrollEdgeAppearance = appearance
        })
    }
}
